package com.bustle.user.dto.authentication;

import java.util.List;
import java.util.Vector;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.xml.bind.annotation.XmlRootElement;

@Path("/authentication/")
@Produces(
  {
    MediaType.APPLICATION_XML
  })
@Stateless
public class AuthenticationDtoDaoWebService
{
  @POST
  @Path("/create")
  public AuthenticationDto create(AuthenticationDto anAuthenticationDto)
  {
    authenticationDtoDao.create(anAuthenticationDto);
    return anAuthenticationDto;
  }

  @GET
  @Path("/retrieve")
  public AuthenticationDto retrieve(@QueryParam("key") String aKey)
  {
    return authenticationDtoDao.retrieve(aKey);
  }

  @GET
  @Path("/retrieveAll")
  public AuthenticationDtoList retrieveAll()
  {
    AuthenticationDtoList all = new AuthenticationDtoList();
    all.setAuthentication(authenticationDtoDao.retrieveAll());
    return all;
  }

  @PUT
  @Path("/update")
  public Response update(AuthenticationDto anAuthenticationDto)
  {
    authenticationDtoDao.update(anAuthenticationDto);
    return Response.status(Status.OK).build();
  }

  @DELETE
  @Path("/delete/{id}")
  public Response delete(@PathParam("login") String aKey)
  {
    authenticationDtoDao.delete(aKey);
    return Response.status(Status.OK).build();
  }

  @EJB
  protected AuthenticationDtoDao authenticationDtoDao;

  @XmlRootElement(name = "authentications")
  static public class AuthenticationDtoList
  {
    public List<AuthenticationDto> getAuthentication()
    {
      return authentication;
    }

    public void setAuthentication(List<AuthenticationDto> aList)
    {
      authentication = aList;
    }

    protected List<AuthenticationDto> authentication = new Vector<>();
  }
}
